import printerModel from '@/model/printer'

// 打印操作
export default {
  data: {},

  // 载入数据
  load(data) {
    // 获取原模版
    this.data = data
    const { version, view } = printerModel.getTemplate(data.type, data.data)

    if(version == 'js') {
      this.jsQrcode(view)
    } else {
      this.pdfQrcode(view)
    }
  },

  // js放入二维码
  jsQrcode(view) {
    view.push({ a: "Line" })
    view.push({ a: 'AlignCenter' })
    view.push({ a: "LineHeight", p: [30] })
    view.push({ a: 'Text', p: [this.data.tbai] })
    view.push({ a: 'QrCode1', p: [this.data.url] })
    
    printerModel.printSmall(view)
  },

  // pdf放入二维码
  pdfQrcode(view) {
    view.content.push({
      svg: '<svg width="300" height="220" viewBox="0 0 300 220"></svg>'
    }, {
      alignment: 'right',
      absolutePosition: { x: 100, y: 630 },
      stack: [{
        text: this.data.tbai,
        fontSize: 10,
        bold: true
      }, {
        margin: [0, 10, 0, 0],
        qr: this.data.url,
        fit: 150
      }]
    })
    
    printerModel.printPDF(this.data.number + '_fiskaly', view)
  }
}